package tiruvury.InterviewPrep.DataStructureTests;

import tiruvury.InterviewPrep.DataStructures.MyLinkedList;
import tiruvury.InterviewPrep.HelperClasses.Node;

public class LinkedListTests
{

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		MyLinkedList list = new MyLinkedList();
		list.CreateRandomList(5);
		list.PrintList();

		System.out.println();
		Node rootNode = list.GetRoot();
		if (rootNode != null)
		{
			System.out.println("Reversing List");
			list.ReverseList(rootNode, null);
			list.PrintList();
		}

		System.out.println();
		list = new MyLinkedList();
		list.CreateRandomList(11);
		list.PrintList();
		list.IterativeReverseList();
		list.PrintList();

		System.out.println();
		int[] data = new int[]
		{ 93, 0, 0, 0, 1, 93, 0, 0, 2, 0, 92, 01, 03, 94, 93, 91, 92 };
		list = new MyLinkedList();
		list.CreateSpecificList(data);
		list.RemoveDuplicates();
		list.PrintList();

		System.out.println();
		data = new int[]
		{ 93, 0, 0, 0, 1, 93, 0, 0, 2, 0, 92, 01, 03, 94, 93, 91, 92 };
		list = new MyLinkedList();
		list.CreateSpecificList(data);
		list.RemoveDuplicatesWithoutBuffer();
		list.PrintList();

		System.out.println();
		data = new int[]
		{ 93, 0, 0, 0, 1, 93, 0, 0, 2, 0, 92, 1, 3, 94, 93, 91, 92 };
		list = new MyLinkedList();
		list.CreateSpecificList(data);
		list.PartitionAndJoinAroundX(2);
		list.PrintList();

		System.out.println();
		data = new int[]
		{ 95, 0, 4, 0, 1, 96, 0, -1, 2, 0, 92, 1, 3, 94, 93, 91, 92 };
		list = new MyLinkedList();
		list.CreateSpecificList(data);
		list.PartitionAndJoinAroundX1(2);
		list.PrintList();

		System.out.println();
		data = new int[]
		{ 93, 0, 0, 0, 1, 93, 0, 0, 2, 0, 92, 1, 3, 94, 93, 91, 92 };
		list = new MyLinkedList();
		list.CreateSpecificList(data);
		int k = 17;
		Node node = list.GetKthToLastNOde(k);
		list.PrintList();
		System.out.println();
		System.out.println("The " + k + "th to last node in the list is: " + ((node != null) ? node.data : ""));

		System.out.println();
		data = new int[]
		{ 1, 3, 2, 4, 3, 1 };
		list = new MyLinkedList();
		list.CreateSpecificList(data);
		list.PrintList();
		System.out.println();
		System.out.println("The list" + (list.IsListPalindrome() ? " is " : " is not ") + "a palindrome");

		System.out.println();
		list = new MyLinkedList();
		list.CreateRandomList(0);
		list.PrintList();
		Node mid = list.FindMiddle();
		System.out.println();
		System.out.println("The middle is " + ((mid != null) ? mid.data : "NULL"));

		System.out.println();
		data = new int[]
		{ 2, 3, 3, 5 };
		list = new MyLinkedList();
		list.CreateSpecificList(data);
		list.PrintList();
		Node nodeToInsert = new Node(6, null);
		list.InsertNodeToSortedList(nodeToInsert);
		System.out.println();
		list.PrintList();
	}
}
